﻿using System;
using System.Collections;
using System.Data;
using System.Web.UI.WebControls;


public partial class EmployeeEquipment : System.Web.UI.Page
{
    private readonly DirectServiceSupplier _DirectServiceSupplier = new DirectServiceSupplier();
    private int employeeId = 0;
    private string codeNumber = string.Empty;
    private ConnectionBase sgbdr;
    protected void Page_Load(object sender, EventArgs e)
    {
        DataTable table = new DataTable();
        DataTable table1 = new DataTable();

        employeeId = GetEmployeeId();
        pnlBody.Visible = employeeId == 0 ? false : true;
        if (employeeId == 0) return;


        if (employeeId != 0)
        {
            txtHiddenTypeId.Text = employeeId.ToString();
            lblEquipmentTypeId.Text = employeeId.ToString();
            table = _DirectServiceSupplier.GetEmployeeEquipmentDisplayedByEmployeeId(employeeId.ToString());
            IList list = new ArrayList();
            foreach (DataRow row in table.Rows)
            {
                codeNumber = row["CodeNumber"].ToString();
                list.Add(codeNumber);
            }
            if (list.Count > 0)
            {
                for (int j = 0; j < list.Count; j++)
                {
                    
                    table1 = _DirectServiceSupplier.GetSpartartByCodeNumber(list[j].ToString());
                    // Response.Write(table1.Rows.Count.ToString()); 
                    if (table1.Rows.Count > 0)
                    {
                        string codeNumber1 = list[j].ToString(); 
                        //lblCodeNumber.Text = "Equipment code:" + codeNumber.ToString();
                       // lblCodeNumber.Visible = true;
                        TableRow headerRow = new TableRow();
                       
                        headerRow.CssClass = "GridViewHeader";
                        // header 

                        
                        //Display codeNumber as header

                        TableHeaderCell headerCell = new TableHeaderCell();
                        //headerCell.ColumnSpan = 5;
                        headerCell.Text = string.Empty;
                        headerRow.Cells.Add(headerCell);

                        headerCell = new TableHeaderCell();
                        headerCell.Text = string.Empty;
                        headerRow.Cells.Add(headerCell);

                        headerCell = new TableHeaderCell();
                        headerCell.Text = string.Empty;
                        headerRow.Cells.Add(headerCell);


                        headerCell = new TableHeaderCell();
                       // headerCell = new TableHeaderCell();
                        headerCell.Text = "Equipment code:" + codeNumber1.ToString();
                       
                        headerRow.Cells.Add(headerCell);
                         


                         headerCell = new TableHeaderCell();
                         headerCell.Text = string.Empty;
                         headerRow.Cells.Add(headerCell);

                         headerCell = new TableHeaderCell();
                         headerCell.Text = string.Empty;
                         headerRow.Cells.Add(headerCell);

                         headerCell = new TableHeaderCell();
                         headerCell.Text = string.Empty;
                         headerRow.Cells.Add(headerCell);

                         Table1.Rows.Add(headerRow);


                        //Display all Header;
                        TableRow headerRowAll = new TableRow();
                        TableHeaderCell headerCellAll = new TableHeaderCell();
                        headerCellAll.Text = "ID";
                        headerRowAll.Cells.Add(headerCellAll);

                        headerCellAll = new TableHeaderCell();
                        headerCellAll.Text = "Model";
                        headerRowAll.Cells.Add(headerCellAll);

                        headerCellAll = new TableHeaderCell();
                        headerCellAll.Text = "Type";
                        headerRowAll.Cells.Add(headerCellAll);


                        headerCellAll = new TableHeaderCell();
                        headerCellAll.Text = "System";
                        headerRowAll.Cells.Add(headerCellAll);

                        headerCellAll = new TableHeaderCell();
                        headerCellAll.Text = "Date purchase";
                        headerRowAll.Cells.Add(headerCellAll);

                        headerCellAll = new TableHeaderCell();
                        headerCellAll.Text = "Date create";
                        headerRowAll.Cells.Add(headerCellAll);

                        headerCellAll = new TableHeaderCell();
                        headerCellAll.Text = "Warranty";
                        headerRowAll.Cells.Add(headerCellAll);
                        Table1.Rows.Add(headerRowAll);



                        for (int k = 0; k < table1.Rows.Count; k++)
                        {
                            TableRow rows = new TableRow();
                            rows.CssClass = "AlternativeRowStyle";
                            TableCell cell = new TableCell();
                            cell.Text = table1.Rows[k]["SPAREPARTID"].ToString();
                            rows.Cells.Add(cell);
                            //rows.Cells

                            TableCell cell1 = new TableCell();
                            cell1.Text = table1.Rows[k]["MODEL"].ToString(); ;
                            rows.Cells.Add(cell1);
                            Table1.Rows.Add(rows);

                            TableCell cell2 = new TableCell();
                            cell2.Text = table1.Rows[k]["TYPEEQUIPMENT"].ToString(); ;
                            rows.Cells.Add(cell2);
                            Table1.Rows.Add(rows);

                            TableCell cell3 = new TableCell();
                            cell3.Text = table1.Rows[k]["SYSTEM"].ToString(); ;
                            rows.Cells.Add(cell3);
                            Table1.Rows.Add(rows);

                            TableCell cell4 = new TableCell();
                            cell4.Text = table1.Rows[k]["PURCHASEDATE"].ToString(); ;
                            rows.Cells.Add(cell4);
                            Table1.Rows.Add(rows);

                            TableCell cell5 = new TableCell();
                            cell5.Text = table1.Rows[k]["DATECREATION"].ToString(); ;
                            rows.Cells.Add(cell5);
                            Table1.Rows.Add(rows);

                            TableCell cell6 = new TableCell();
                            cell6.Text = table1.Rows[k]["ISWARRANTY"].ToString(); ;
                            rows.Cells.Add(cell6);
                            Table1.Rows.Add(rows);

                             

                        }

                    }
                }
            }
        }
    }
      
    public int GetEmployeeId()
    {
        return !String.IsNullOrEmpty(Request.QueryString["employeeId"]) ? Int32.Parse(Request.QueryString["employeeId"]) : 0;
    }

}
